﻿using System.Globalization;
using System.Linq;
using System.Web.Mvc;
using Project.DAL.Repository;
using Project.Domain.Entities;

namespace Project.WebUI.Controllers
{    
    public class HomeController : Controller
    {
        private readonly IUserRepository _userRepository;
        private readonly IAnnouncementRepository _announcementRepository;
        private readonly IBetRepository _betRepository;
        private readonly IMatchesRepository _matchesRepository;

        public HomeController(IUserRepository userRepository,
            IAnnouncementRepository announcementRepository,
            IBetRepository betRepository,
            IMatchesRepository matchesRepository)
        {
            _userRepository = userRepository;
            _announcementRepository = announcementRepository;
            _betRepository = betRepository;
            _matchesRepository = matchesRepository;
        }

        public ActionResult ChangeCulture(string lang, string returnUrl)
        {
            Session.Remove("Culture");
            Session["Culture"] = new CultureInfo(lang);
            return Redirect(returnUrl);
        }
        
        public ActionResult Index()
        {          
            return View();
        }   
     
        public ActionResult GetNews()
        {
            var news = _announcementRepository.GetMany(null, n => n.OrderByDescending(t => t.CreatedTime));
            return PartialView("_GetNews", news);
        }
    }
}
